<?php

namespace  app\taglib;

use think\Template;
use think\template\TagLib;

class HcTaglib extends TagLib
{

    protected $siteId;
    protected $sellerId;
    protected $lang;

    /**
     * @throws \app\exception\ModelException
     */
    public function __construct(Template $template)
    {
        $this->getDomain();
        parent::__construct($template);
    }

    // 标签定义
    protected $tags = [
        // 标签定义： attr 属性列表 close 是否闭合（0 或者1 默认1） alias 标签别名 level 嵌套层次
        // 上一篇
        'precontent' => ['attr'=>'','close'=>0],
        // 下一篇
        'nextcontent' => ['attr'=>'','close'=>0],
        // 推荐文章
        'recommend' => ['attr'=>'cid,moduleId','close'=>1],
        // 配置
        'setting' => ['attr=>name,type','close'=>0],
        // 面包屑
        'breadcrumb'       => ['attr' => 'cid', 'close' => 1],
        // 广告
        'advertise' => ['attr'=>'id','close'=>0],
        // 内容
        'contentpage' => ['attr'=>'page,limit,mainField,subField,isTop,isCommend','close'=>1],
        'content' => ['attr'=>'cid,mainField,subField,sort,limit,asPage,isTop,isCommend','close'=>1],
        'tagContent'   => ['attr'],
        'contentDetail' => ['attr'=>'id'], 
        // 栏目
        'subcategory'    => ['attr' => 'pid', 'close' => 1],//非必须属性item
        'allsubcategory' => ['attr' => 'pid', 'close' => 1],//非必须属性item
        'categorylist'       => ['attr' => 'ids,where,order', 'close' => 1],//非必须属性item
        'category'         => ['attr' => 'id','close' => 1],//非必须属性item
        // 导航
        'navigation'   => ['attr'=>'nav-id,','close'=>1],
        'navigationmenu'   => ['attr'=>'cid,item','close'=>1],
        'navigationfolder'   => ['attr'=>'cid,item','close'=>1],
        // 导航数据
        'nav' => ['attr'=>'cid'],

        // 友情链接
        'link'  => ['attr'=>'','close'=>1],
        // 幻灯片
        'slide' => ['attr' =>'cid,item','close'=>1]
    ];

    public function tagNextContent($tag,$content): string
    {
        $id = (int)request()->param('id');
        $cid = (int)request()->param('cid');
        $sellerId = $this->sellerId;
        return  <<<parse
<?php
    \$nextContent = \app\service\ContentService::getNextContent([
    'id' => {$id},
    'cid' => {$cid},
    'seller_id' => {$sellerId},
    'website_id' => {$this->siteId},
    'lang' => '{$this->lang}'
]);
if(!empty(\$nextContent)){
    \$nextId = \$nextContent['id'];
    \$nextCid = {$cid};
    \$nextTitle = \$nextContent['title'];
}
?>
{if condition = "empty(\$nextContent)" }
<a href="javascript:;">没有了</a>
{else /}
下一篇：<a href="{:hcUrl('Detail/index',['id'=>\$nextId,'cid'=>\$nextCid ])}">{\$nextTitle}</a>
{/if}
parse;

    }


    public function tagPreContent($tag,$content): string
    {
        $id = (int)request()->param('id');
        $cid = (int)request()->param('cid');
        $sellerId = $this->sellerId;
        return  <<<parse
<?php
    \$preContent = \app\service\ContentService::getPreContent([
    'id' => {$id},
    'cid' => {$cid},
    'seller_id' => {$sellerId},
    'website_id' => {$this->siteId},
    'lang' => '{$this->lang}'
]);
if(!empty(\$preContent)){
    \$preId = \$preContent['id'];
    \$preCid = {$cid};
    \$preTitle = \$preContent['title'];
}else{
    \$listId = {$cid};
}
?>
{if condition="empty(\$preContent)" }
<a href="{:hcUrl('List/index',['id'=>\$listId])}">返回列表</a>
{else /}
上一篇：<a href="{:hcUrl('Detail/index',['id'=>\$preId,'cid'=>\$preCid])}">{\$preTitle}</a>
{/if}
parse;

    }



    public function tagRecommend($tag,$content)
    {
        $cid          =  empty($tag['cid']) ? '' : $tag['cid'];
        $moduleId     =  empty($tag['moduleId']) ? 0 : $tag['moduleId'];
        $mainField    =  empty($tag['mainField']) ? '*' : $tag['mainField'];
        $item         =  empty($tag['item']) ? 'vo' : $tag['item'];
        $subField     =  isset($tag['subField']) ? '*' : '';
        $sort         =  empty($tag['sort']) ? 'publish_time desc' : $tag['sort'];
        $limit        =  empty($tag['limit']) ? 8 : $tag['limit'];
        $isCommend    =  empty($tag['isCommend']) ? 2 : (int)$tag['isCommend'];
        $isTop        =  empty($tag['isTop']) ? 2 : (int)$tag['isTop'];
        $asPage       =  empty($tag['asPage']) ? false : $tag['asPage'];
        $all          =  empty($tag['all']) ? 2 : $tag['all'];
        $page         = empty($tag['page']) ? 2 : $tag['page'];
        $returnVarName = empty($tag['name']) ? 'hc_recommend' : $tag['name'];
        if (strpos($cid, '$') === 0) {
            $this->autoBuildVar($cid);
        } else {
            $cid  = "'{$cid}'";
        }
        return <<<parse
<?php
\${$returnVarName} = \app\service\ContentService::getTagRecommend([
    'cid'  => {$cid},
    'module_id' => {$moduleId},
    'item'  => '{$item}',
    'mainField' => '{$mainField}',
    'subField'  => '{$subField}',
    'sort'  => '{$sort}',
    'limit' => '{$limit}',
    'isTop' => {$isTop},
    'isCommend'     => {$isCommend},
    'siteId'        => {$this->siteId},
    'lang'        => '{$this->lang}',
    'asPage'        => '{$asPage}',
    'page'          => '{$page}',
    'all'           => '{$all}',
    'sellerId'      => {$this->sellerId},
]);
?>
    {foreach name="{$returnVarName}" id="{$item}"}
    {$content}
    {/foreach}
parse;

    }

    
    public function tagAdvertise($tag,$content): string
    {
        // tyoe 1 文字 2 图片 3 视频
        $id = empty($tag['id']) ? 0 : (int)$tag['id'];
        $class = empty($tag['class']) ? '' : $tag['class'];
        if (!empty($id)) {
            $this->autoBuildVar($id);
        }
        return <<<parse
<?php
if(!empty({$id})){
    \$_advertise_ = \app\service\ApiService::getAdvertisement({$id},{$this->sellerId});
    \$url = '';
    if(\$_advertise_['type'] != 1){
        \$url = empty(\$_advertise_['attachment']['url']) ? '' : \$_advertise_['attachment']['url'];
    }
?>
{if condition="\$_advertise_['type'] == 1"}
<a href="{\$_advertise_['url']}" target="_blank" class="{$class}">{\$_advertise_['title']}</a>
{elseif condition="\$_advertise_['type'] == 2" /}
<a href="{\$_advertise_['url']}" target="_blank" class="{$class}">
    <img src="{\$url}" />
</a>
{else /}
<a href="{\$url}" target="_blank" class="{$class}">
    <video src="{\$url}" >您的浏览器不支持 video 标签。</video>
</a>
{/if}
<?php
}
?>
{$content}
parse;
    }

    /**
     * 内容详情
     * @param $tag
     * @param $content
     * @return string
     */
    public function tagContentDetail($tag, $content): string
    {
        $id = empty($tag['id']) ? '0' : $tag['id'];
        if (!empty($id)) {
            $this->autoBuildVar($id);
        }
        $returnVarName = empty($tag['name']) ? 'hc_breadcrumb' : $tag['name'];
        return <<<parse
<?php
if(!empty({$id})){
    \${$returnVarName}= \app\service\ContentService::getTagContentDetail({$id},{$this->sellerId},{$this->lang},{$this->siteId});
?>
  {$content}
<?php
}
?>
parse;
    }


    /**
     * 面包屑标签
     */
    public function tagBreadcrumb($tag, $content): string
    {
        $cid = empty($tag['cid']) ? '0' : $tag['cid'];
        $item = empty($tag['item']) ? 'vo' : $tag['item'];
        $onlyData = empty($tag['onlyData']) ? '2' : '1';
        if (strpos($cid, '$') === 0) {
            $this->autoBuildVar($cid);
        }
        $returnVarName = empty($tag['name']) ? 'hc_breadcrumb' : $tag['name'];
        if($onlyData == 1){
            $parse =  <<<parse
<?php
if(!empty({$cid})){
    \${$returnVarName}= \app\service\ApiService::getBreadcrumb({$cid},{$this->siteId},{$this->siteId},'{$this->lang}');
?>
    {$content}
<?php
}
?>
parse;
        }else{
        $parse =  <<<parse
<?php
if(!empty({$cid})){
    \${$returnVarName} = \app\service\ApiService::getBreadcrumb({$cid},{$this->siteId},{$this->siteId},'{$this->lang}');
?>

{foreach name="{$returnVarName}" id="{$item}"}
    {$content}
{/foreach}

<?php
}
?>
parse;
}
        return $parse;
    }

    /**
     * 配置标签
     * @param $tag
     * @param $content
     * @return string
     */
    public function tagSetting($tag,$content):string
    {
        $name = empty($tag['name']) ? '' : $tag['name'];
        $type = empty($tag['type']) ? 2 : $tag['type'];
        $returnVarName = empty($tag['name']) ? 'hc_setting' : $tag['name'];
        return  <<<parse
<?php 
\${$returnVarName} = \app\service\ApiService::tagSetting([
    'name'  => '{$name}',
    'type' => '{$type}',
    'siteId'        => {$this->siteId},
    'lang'        => '{$this->lang}',
    'sellerId'      => {$this->sellerId},
]);
?>
{\${$returnVarName}}
{$content}
parse;
    }

    /**
     * 内容分页
     * @param $tag
     * @param $content
     * @return string
     */
    public function tagContentPage($tag,$content): string
    {
        $item         =  empty($tag['item']) ? 'vo' : $tag['item'];
        $mainField    =  empty($tag['mainField']) ? '' : $tag['mainField'];
        $subField     =  isset($tag['subField']) ? '*' : '';
        $limit        =  empty($tag['limit']) ? 15 : $tag['limit'];
        $sort         =  empty($tag['sort']) ? 'publish_time desc' : $tag['sort'];
        $isTop        =  empty($tag['isTop']) ? 2 : (int)$tag['isTop'];
        $isCommend    =  empty($tag['isCommend']) ? 2 : (int)$tag['isComment'];
        $onlyData     =  empty($tag['onlyData']) ? 2 : $tag['onlyData'];
        $page = empty($tag['page']) ? 1 : $tag['page'];
        $returnVarName = empty($tag['name']) ? 'hc_content_page' : $tag['name'];
        if($onlyData == 1){
            $parse = <<<parse
<?php
\${$returnVarName} = \app\service\ContentService::tagContentPage([
    'item'  => '{$item}',
    'mainField' => '{$mainField}',
    'subField'  => '{$subField}',
    'sort'  => '{$sort}',
    'limit' => '{$limit}',
    'page' => '{$page}',
    'isTop' => {$isTop},
    'isCommend'     => {$isCommend},
    'siteId'        => {$this->siteId},
    'lang'        => '{$this->lang}',
    'sellerId'      => {$this->sellerId},
    'asPage'    => '1',
    'onlyData'  => '1',
     ]);
?>
 {$content}

parse;

        }else{
            $parse =<<<parse
<?php
\${$returnVarName} = \app\service\ContentService::tagContentPage([
    'item'  => '{$item}',
    'mainField' => '{$mainField}',
    'subField'  => '{$subField}',
    'sort'  => '{$sort}',
    'limit' => '{$limit}',
    'page' => '{$page}',
    'isTop' => {$isTop},
    'isCommend'     => {$isCommend},
    'siteId'        => {$this->siteId},
    'lang'        => '{$this->lang}',
    'sellerId'      => {$this->sellerId},
    'asPage'    => '1',
    'onlyData'  => '2',
]);

?>
    {foreach name="{$returnVarName}" id="{$item}"}
    {$content}
    {/foreach}
parse;
        }

        return $parse;
    }

    /**
     * 内容列表
     * @param $tag
     * @param $content
     * @return string
     */
    public function tagContent($tag,$content): string
    {
        // 1 true 2 false
        $cid          =  empty($tag['cid']) ? '' : $tag['cid'];
        $moduleId     =  empty($tag['moduleId']) ? 0 : $tag['moduleId'];
        $item         =  empty($tag['item']) ? 'vo' : $tag['item'];
        $mainField    =  empty($tag['mainField']) ? '*' : $tag['mainField'];
        $subField     =  isset($tag['subField']) ? '*' : '';
        $sort         =  empty($tag['sort']) ? 'publish_time desc' : $tag['sort'];
        $limit        =  empty($tag['limit']) ? null : $tag['limit'];
        $isTop        =  empty($tag['isTop']) ? 2 : (int)$tag['isTop'];
        $isCommend    =  empty($tag['isCommend']) ? 2 : (int)$tag['isComment'];
        $asPage       =  empty($tag['asPage']) ? false : $tag['asPage'];
        $all          =  empty($tag['all']) ? 2 : $tag['all'];
        $page         = empty($tag['page']) ? 1 : $tag['page'];
        $onlyData     =  empty($tag['onlyData']) ? 2 : $tag['onlyData'];
        if (strpos($limit, '$') === 0) {
            $this->autoBuildVar($limit);
        }
        if (strpos($page, '$') === 0) {
            $this->autoBuildVar($page);
        }
        if (strpos($cid, '$') === 0) {
            $this->autoBuildVar($cid);
        } else {
            $cid  = "'{$cid}'";
        }
        $returnVarName = empty($tag['name']) ? 'hc_content' : $tag['name'];
        if($onlyData == 1){
            $parse = <<<parse
<?php
\${$returnVarName} = \app\service\ContentService::tagContentList([
    'cid'  => {$cid},
    'module_id' => {$moduleId},
    'item'  => '{$item}',
    'mainField' => '{$mainField}',
    'subField'  => '{$subField}',
    'sort'  => '{$sort}',
    'limit' => '{$limit}',
    'isTop' => {$isTop},
    'isCommend'     => {$isCommend},
    'siteId'        => {$this->siteId},
    'lang'        => '{$this->lang}',
    'asPage'        => '{$asPage}',
    'page'          => '{$page}',
    'all'           => '{$all}',
    'sellerId'      => {$this->sellerId},
]);
?>
 {$content}
   
parse;

        }else{
            $parse =<<<parse
<?php
\${$returnVarName} = \app\service\ContentService::tagContentList([
     'cid'  => {$cid},
     'module_id' => {$moduleId},
    'item'  => '{$item}',
    'mainField' => '{$mainField}',
    'subField'  => '{$subField}',
    'sort'  => '{$sort}',
    'limit' => '{$limit}',
    'isTop' => {$isTop},
    'isCommend'     => {$isCommend},
    'siteId'        => {$this->siteId},
    'lang'        => '{$this->lang}',
    'asPage'        => '{$asPage}',
    'page'          => '{$page}',
    'all'           => '{$all}',
    'sellerId'      => {$this->sellerId},
]);
?>
    {foreach name="{$returnVarName}" id="{$item}"}
    {$content}
    {/foreach}
parse;
        }

        return $parse;

    }

    /**
     * 所有子分类列表
     * @param $tag
     * @param $content
     * @return string
     */
    public function tagAllSubCategory($tag,$content): string
    {
        $pid      =  empty($tag['pid']) ? '': $tag['pid'];
        $key     = empty($tag['key']) ? '' : $tag['key'];
        $item          = empty($tag['item']) ? 'vo' : $tag['item'];//循环
        $sort         = empty($tag['sort']) ? 'sort asc' : $tag['sort'];
        $maxLevel   = empty($tag['max-level']) ? '0' : $tag['max-level'];
        $field         = empty($tag['field']) ? '*' : $tag['field'];
        if (strpos($pid, '$') === 0) {
            $this->autoBuildVar($pid);
        }
        $returnVarName = 'hc_sub_category';
        return <<<parse
<?php
\${$returnVarName} = \app\service\ApiService::getAllSubCategory({$pid},{$this->sellerId},{$this->siteId},'{$this->lang}',{$maxLevel},'{$sort}','{$field}');
?>
{volist name="{$returnVarName}" id="{$item}" key="{$key}"}
{$content}
{/volist}
parse;
    }

    /**
     * 获取直接子分类
     * @param $tag
     * @param $content
     * @return string
     */
    public function tagSubcategory($tag,$content): string
    {
        $pid           =  empty($tag['pid']) ? 0 : $tag['pid'];
        $item          = empty($tag['item']) ? 'vo' : $tag['item']; //循环
        $sort         = empty($tag['sort']) ? 'sort asc' : $tag['sort'];
        $field         = empty($tag['field']) ? '*' : $tag['field'];
        $returnVarName = 'hc_subcategory';
        if(strpos($pid,'$') === 0 ){
            $this->autoBuildVar($pid);
        }
        return <<<parse
<?php
    \${$returnVarName} = \app\service\ApiService::getSubCategory({$pid},{$this->sellerId},{$this->siteId},'{$this->lang}','{$sort}','{$field}');
?>
{volist name="{$returnVarName}" id="{$item}" }
{$content}
{/volist}
parse;
    }

    /**
     * 分类列表
     * @param $tag
     * @param $content
     */
    public function tagCategoryList($tag,$content): string
    {
        $item          = empty($tag['item']) ? 'vo' : $tag['item'];//循环
        $sort         = empty($tag['sort']) ? 'sort asc' : $tag['sort'];
        $ids      =  empty($tag['ids']) ? '': $tag['ids'];
        $field         = empty($tag['field']) ? 0 : $tag['field'];
        $returnVarName = 'hc_categories';
        return <<<parse
<?php
\${$returnVarName} = \app\service\ApiService::getCategoryList('{$ids}',{$this->sellerId},{$this->siteId},'{$this->lang}','{$sort}','{$field}');
?>
{volist name="{$returnVarName}" id="{$item}"}
{$content}
{/volist}
parse;
    }

    /**
     * 分类详情
     * @param $tag
     * @param $content
     * @return string
     */
    public function tagCategory($tag,$content): string
    {
        $id           = empty($tag['id']) ? 0 : $tag['id'];
        $field         = empty($tag['field']) ? '*' : $tag['field'];

        if (strpos($id, '$') === 0) {
            $this->autoBuildVar($id);
        }
        $returnVarName = empty($tag['item']) ? 'hc_category' : $tag['item'];

        return <<<parse
<?php
\${$returnVarName} = \app\service\ApiService::getCategory({$id},{$this->sellerId},{$this->siteId},'{$this->lang}','{$field}');
?>
{$content}
parse;
    }

    /**
     * 幻灯片
     * @param $tag
     * @param $content
     * @return string
     */
    public function tagSlide($tag,$content): string
    {
        $cid         = empty($tag['cid']) ? '0' : $tag['cid'];
        $item          = empty($tag['item']) ? 'vo' : $tag['item'];//循环
        $field          = empty($tag['field']) ? '*' : $tag['field'];
        $limit         = empty($tag['limit']) ? '' : $tag['limit'];
        $sort         = empty($tag['sort']) ? 'sort asc' : $tag['sort'];
        $returnVarName = 'hc_slide';
        return <<<parse
<?php
\${$returnVarName} = \app\service\ApiService::slide({$cid},{$this->sellerId},'{$field}',{$limit},'{$sort}');
?>
{volist name="{$returnVarName}" id="{$item}"}
{$content}
{/volist}
parse;
    }

    /**
     * 友情链接
     * @param $tag
     * @param $content
     * @return string
     */
    public function tagLink($tag,$content): string
    {
        $ids = empty($tag['ids']) ? null : $tag['ids'];;
        $item          = empty($tag['item']) ? 'vo' : $tag['item'];//循环
        $field          = empty($tag['field']) ? '*' : $tag['field'];
        $limit         = empty($tag['limit']) ? null : (int)$tag['limit'];
        $sort         = empty($tag['sort']) ? 'sort asc' : $tag['sort'];
        $type = empty($tag['type']) ? 2 : (int)$tag['type'];
        $returnVarName = 'hc_link';
        return <<<parse
<?php
\${$returnVarName} = \app\service\ApiService::link('{$ids}',{$this->siteId},{$this->sellerId},'{$this->lang}',{$type},'{$field}','{$limit}','{$sort}');
?>
{volist name="{$returnVarName}" id="{$item}"}
{$content}
{/volist}
parse;
    }

    /**
     * 导航数据标签
     * @param $tag
     * @param $content
     * @return string
     */
    public function tagNav($tag,$content): string
    {
        $cid = empty($tag['cid']) ? 0 : $tag['cid'];
        $item = empty($tag['item']) ? 'vo' : $tag['item'];
        $sort = empty($tag['sort']) ? 'sort desc' : $tag['sort'];
        $offset = empty($tag['offset']) ? 0 : $tag['offset'];
        $maxLevel   = empty($tag['max-level']) ? 0 : intval($tag['max-level']);
        $pid = isset($tag['pid']) ? intval($tag['pid']) : 0;
        $returnVarName = 'hc_nav';
        return <<<parse
<?php
    \${$returnVarName}  = \app\service\ApiService::nav({$cid},{$this->siteId},{$this->sellerId},'{$this->lang}',{$maxLevel},{$pid},'{$sort}');
?>
{volist name="{$returnVarName}" id="{$item}" offset="{$offset}" }
{$content}
{/volist}

parse;
    }

    /**
     * 导航标签
     */
    public function tagNavigation($tag, $content): string
    {
        // nav-id,id,root,class
        $navId                   = isset($tag['nav-id']) ? $tag['nav-id'] : 0;
        $id                      = isset($tag['id']) ? $tag['id'] : '';
        $root                    = isset($tag['root']) ? $tag['root'] : 'ul';
        $class                   = isset($tag['class']) ? $tag['class'] : '';
        $maxLevel                = isset($tag['max-level']) ? intval($tag['max-level']) : 0;
        $pid                     = isset($tag['pid']) ? intval($tag['pid']) : 0;
        $parseNavigationFuncName = '__parse_navigation_' . md5($navId.$id.$class);
        if (strpos($navId, '$') === 0) {
            $this->autoBuildVar($navId);
        } else {
            $navId = "'{$navId}'";
        }
        $parse = <<<parse
<?php
/*start*/
if (!function_exists('{$parseNavigationFuncName}')) {
    function {$parseNavigationFuncName}(\$menus){
        \$_parse_navigation_func_name = '{$parseNavigationFuncName}';
?>
        {foreach name="menus" item="menu" }
        {$content}
        {/foreach}
        
<?php 
    }
}
/*end*/
?>

<?php
    \$menus  = \app\service\ApiService::nav({$navId},{$this->siteId},{$this->sellerId},'{$this->lang}',{$maxLevel},{$pid});
?>


{if condition="'{$root}'==''" }
    {:{$parseNavigationFuncName}(\$menus)}
{else/}
    <{$root} id="{$id}" class="{$class}">
        {:{$parseNavigationFuncName}(\$menus)}
    </{$root}>
{/if}

parse;
        return $parse;
    }

    /**
     * 导航menu标签
     */
    public function tagNavigationMenu($tag, $content): string
    {
        //root,class
        $root  = empty($tag['root']) ? '' : $tag['root'];
        $class = empty($tag['class']) ? '' : $tag['class'];
        if (empty($root)) {
            $parse = <<<parse
{if condition="empty(\$menu['children'])"}
    {$content}
{/if}
parse;
        } else {
                $parse = <<<parse
{if condition="empty(\$menu['children'])"}
    <{$root} class="{$class}" >
    {$content}
    </{$root}>
{/if}
parse;
        }
        return $parse;
    }

    /**
     * 导航folder标签
     */
    public function tagNavigationFolder($tag, $content): string
    {
        //root,class,dropdown,dropdown-class
        $root          = empty($tag['root']) ? 'li' : $tag['root'];
        $class         = empty($tag['class']) ? '' : $tag['class'];
        $dropdown      = empty($tag['dropdown']) ? 'ul'  : $tag['dropdown'];
        $dropdownClass = empty($tag['dropdown-class']) ? '' : $tag['dropdown-class'];
        $parse =  <<<parse
{if condition="!empty(\$menu['children'])"}
    <{$root} class="{$class}">
        {$content}
        <{$dropdown} class="{$dropdownClass}">
            {php}echo \$_parse_navigation_func_name(\$menu['children']);{/php}
        </{$dropdown}>
    </{$root}>
{/if}
parse;
        return $parse;
    }

    /**
     * 配置sellerId和siteId
     * @throws \app\exception\ModelException
     * @throws \Exception
     */
    public function getDomain()
    {
        if(hcInstalled()){
            if(request()->baseUrl() !== '/install_complete'){
                if(!empty(INDEX_SITE_ID)){
                    // 前台
                    $siteId = INDEX_SITE_ID;
                    $sellerId = INDEX_SELLER_ID;
                    $lang = INDEX_LANG;
                }else{
                    // 后台
                    $siteId = ADMIN_SITE_ID;
                    $sellerId = ADMIN_SELLER_ID;
                    $lang = ADMIN_LANG;
                    if(!$siteId || !$sellerId ||!$lang){
                        throw new \Exception('参数错误');
                    }
                }
            }else{
                $sellerId = 0;
                $siteId = 0;
                $lang = '';
            }
        }else{
            $sellerId = 0;
            $siteId = 0;
            $lang = '';
        }

        $this->setSellerId($sellerId);
        $this->setSiteId($siteId);
        $this->setLang($lang);
    }

    public function setLang($lang)
    {
        return $this->lang = $lang;
    }

    public function setSiteId($siteId)
    {
        return $this->siteId = $siteId;
    }

    public function setSellerId($sellerId)
    {
        return $this->sellerId = $sellerId;
    }

}